#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <sys/un.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

int main()
{
        // 清理文件
        unlink("server_socket");
                int server_sockfd;
                struct sockaddr_un server_address;
                int server_len;
                server_len = sizeof(server_address);
        // 创建套接字
        server_sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
        // 绑定套接字
        server_address.sun_family = AF_UNIX;
        strcpy(server_address.sun_path, "server_socket");
        bind(server_sockfd, (struct sockaddr *)&server_address, server_len);
        // 监听模式
        listen(server_sockfd, 5);
                int client_sockfd;
                struct sockaddr_un client_address;
                int client_len;
                client_len = sizeof(client_address);
        while (1)
        {
                char ch='A';
                printf("server waiting\n");
                // 接受连接
                client_sockfd = accept(server_sockfd, (struct sockaddr *)&server_address, (socklen_t *)&client_len);
                write(client_sockfd, &ch, 1);
                close(client_sockfd);
        }
}
